// pages/classify/classify.js
//引入api文件  直接找里面的default
const api = require("../../utils/api.js").default;
const myRequest = require("../../utils/request.js").default;
Page({

  /**
   * 页面的初始数据
   */
  data: {
      color:true,
      categoryList:[],
      currentCategory:[],
      show:false,
      fenleiID:"",
      item:"",
      selAddress:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '正在加载中喔',
      success: this.onshower("options", options)
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },


  //当前分类
  fenlei(e){
    const self = this;
    var goodsid = e.currentTarget.dataset.goodsid;
    this.setData({
      fenleiID : goodsid
    });
    wx.navigateTo({
      url: '/pages/classify/classify?goodsid=' + goodsid,
      success:function(res){
        console.log("分类",res)
      }
    });
    wx.request({
      url: api.catalog_current + "?id=" + goodsid,
      success:function(res){
        self.setData({
          fenleiID : res.data.data.currentCategory.id,
          currentCategory: res.data.data.currentCategory,
          subCategoryList: res.data.data.currentCategory.subCategoryList,
          
          
        })  
        console.log("当前分类", self.data.currentCategory.subCategoryList);
      }

    })
  },
  

  //分类列表
  categorylist(e){
    const self = this;
    var categorylistid = e.currentTarget.dataset.categorylistid;
    console.log(this.data.fenleiID)
    console.log(categorylistid)
    wx.navigateTo({
      url: '/pages/list/list?categorylistid=' + this.data.fenleiID + "&subCategoryList=" + categorylistid,
    success:function (res) {
            console.log("分类列表",res);
      }
    })
  },


  //分类
  onshower(){
    var self = this;
    self.setData({
      show:false
    });
    wx.request({
      url: api.catalog,
      success: function (res) {
        console.log("cart", res);
        self.setData({
          //分类
          categoryList: res.data.data.categoryList,
          fenleiID: res.data.data.currentCategory.id
        })
        console.log(self.data.categoryList)
      }
    }),
      wx.request({
        url: api.catalog_current + "?id=" + "1005000",
        success: function (res) {
          self.setData({
            currentCategory: res.data.data.currentCategory,
            subCategoryList: res.data.data.currentCategory.subCategoryList
          })
          console.log("当前分类", self.data.currentCategory.subCategoryList);
          wx.hideLoading();
        }
      })
  },


  pinpai(){
    const self = this;
    this.setData({
      show : !this.show
    })
    
    wx.request({
      url: api.brandList,
      success:function(res){
        self.setData({
          brand : res.data.data.data
        })
        console.log("品牌",self.data.brand)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
      
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
})